﻿@model ImageWeb.Models.LoginModel
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")
    <link rel="stylesheet" href="/Content/Control.css" />
    <title></title>
</head>
<body>
    <div>
        <div class="loginform">
            <div class="form-horizontal">
                <h2 class="text-primary">EL图片管理后台系统</h2>
                @using (Html.BeginForm())
                {
                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                    <div class="form-group form-group-lg">
                        <input class="form-control" placeholder="员工编号" data-val="true" data-val-length="工号长度为1-10个字符" data-val-length-max="10" data-val-length-min="1" data-val-required="必须输入" id="userNum" name="userNum" type="text" value="">
                        @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
                    </div>
                    <div class="form-group form-group-lg">
                        <input class="form-control" placeholder="密码" data-val="true" data-val-length="密码长度6-20个字符" data-val-length-max="20" data-val-length-min="6" data-val-required="必须输入密码" id="Password" name="Password" type="password" value="">
                        @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
                    </div>
                    <div class="form-group form-group-lg" style="display:none" id="div_valiCode">
                        <input type="text" style="display:none" value="" name="cnt" id="cnt" />
                        <input class="form-control" id="valicode" name="valicode" type="text" value="" placeholder="验证码">
                        @Html.ValidationMessageFor(model => model.valicode, "", new { @class = "text-danger" })
                        <p></p>
                        <img id="img_valiCode" style="cursor: pointer;" src="CetValidateCode" alt="验证码" />
                    </div>
                    <div class="form-group form-group-lg">
                        <a href="#" data-toggle="modal" data-target="#ForgetModel">忘记密码</a>
                        <input type="submit" id="login" value="登录" class="btn btn-default pull-right" />
                        <br /><br />
                        <a href="Register" style="padding-left:320px">注册</a>
                    </div>
                }
            </div>
        </div>
        <div class="modal fade" id="ForgetModel" tabindex="-1" role="dialog" aria-labelledby="ForgetModelLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="ModalLabel">忘记密码</h4>
                    </div>
                    <div class="modal-body">
                        <div class="alert-danger" role="alert" id="f_message" style="display:none"><span class="glyphicon glyphicon-remove" id="f_msg"></span></div>
                        <table border="0" width="500">
                            <tr>
                                <td>
                                    <input id="email" placeholder="您的邮箱" class="form-control" style="margin-left: 68px" />
                                    <p></p>
                                    <input id="fCode" placeholder="验证码" class="form-control" style="margin-left: 68px" />
                                    <p></p>
                                    <img id="img_fvaliCode" style="cursor: pointer; margin-left: 68px" src="CetValidateCode" alt="验证码" />
                                </td>
                            </tr>
                        </table>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" id="f_save">提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="ReigsterModel" tabindex="-2" role="dialog" aria-labelledby="ReigsterModelLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="ModalLabel">注册</h4>
                    </div>
                    <div class="modal-body">
                        <div class="alert-danger" role="alert" id="f_message" style="display:none"><span class="glyphicon glyphicon-remove" id="f_msg"></span></div>
                        <table border="0" width="500">
                            <tr>
                                <td>
                                    <input id="usernum" placeholder="员工编号" class="form-control" style="margin-left: 68px" />
                                    <p></p>
                                    <input id="password" placeholder="密码" type="password" class="form-control" style="margin-left: 68px" />
                                    <p></p>
                                    <input id="confirm_password" placeholder="确认密码" type="password" class="form-control" style="margin-left: 68px" />
                                    <p></p>
                                    <input id="name" placeholder="姓名" class="form-control" style="margin-left: 68px" />
                                    <p></p>
                                    <input id="email" placeholder="您的邮箱(用于找回密码)" class="form-control" style="margin-left: 68px" />
                                    <p></p>
                                    <input id="validatecode" placeholder="验证码" class="form-control" style="margin-left: 68px" />
                                    <p></p>
                                    <img id="img_rvaliCode" style="cursor: pointer; margin-left: 68px" src="CetValidateCode" alt="验证码" />
                                </td>
                            </tr>
                        </table>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" id="r_save">提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

@Scripts.Render("~/bundles/bootstrap")
<script type="text/javascript" src="~/Plug/layui/layui.all.js"></script>
<script src="/Scripts/CookieOperation.js"></script>
<script>
    $(function () {
        if (!getCookie("logincnt")) {
            setCookie("logincnt", 0);
        }
        if (getCookie("logincnt") > 2) {
            $('#div_valiCode').show();
            document.getElementById('cnt').value = getCookie("logincnt");
        }
        $("#img_valiCode").bind("click", function () {
            this.src = "CetValidateCode?time=" + (new Date()).getTime();
        });
        $("#img_fvaliCode").bind("click", function () {
            this.src = "CetValidateCode?time=" + (new Date()).getTime();
        });
        $("#img_rvaliCode").bind("click", function () {
            this.src = "CetValidateCode?time=" + (new Date()).getTime();
        });
    });

    $("#f_save").click(function () {
        var v_code = "";
        var email = document.getElementById("email").value;
        var f_code = document.getElementById("fCode").value;
        layer.load();
        if (typeof (email) == 'undefined' || typeof (f_code) == 'undefined') {
            layer.alert("邮箱和验证码均不可为空", { icon: 0 });
        }
        else {
            $.ajax({
                url: "ForgetPwd1",
                data: { email: email, _code: f_code },
                type: "get",
                success: function (json) {
                    layer.closeAll('loading');
                    if (json.code == 0) {
                        layer.alert(json.info);
                    }
                    else {
                        $("#ForgetModel").toggle();
                        layer.prompt({ title: '输入您收到的识别码，并确认', formType: 0 }, function (pass, index) {
                            layer.load();
                            layer.close(index);
                            v_code = pass;
                            $.ajax({
                                url: "ForgetPwd2",
                                data: { f_Validate: pass },
                                type: "get",
                                success: function (json2) {
                                    layer.closeAll('loading');
                                    if (json2.code == 0) {
                                        layer.alert(json2.info);
                                    }
                                    else {
                                        layer.prompt({ title: '请输入您的新登录密码，并确认', formType: 1 }, function (pwd, second) {
                                            layer.load();
                                            $.ajax({
                                                url: "ForgetPwd3",
                                                data: { email: email, newPwd: pwd, flag: true, f_Validate: v_code },
                                                type: "post",
                                                success: function (json3) {
                                                    layer.closeAll('loading');
                                                    layer.close(second);
                                                    layer.alert(json3.info);
                                                }
                                            })
                                        })
                                    }
                                }
                            })
                        })
                    }

                },
                error: function () {
                    layer.msg("网络错误", { icon: 2 })
                }
            })
        }
    })


</script>
